package com.yunwushanhe.entity;

import com.yunwushanhe.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 这个类是 SpringSecurity 的需要对 user 实体类的扩展
 * 为了迎合 UserDetailsServiceImpl 中的 loadUserByUsername 方法
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements UserDetails {

    private User user;
    private List<String> permissionList;

    public LoginUser(User user) {
        this.user = user;
    }

    @Override // 这个方法涉及到权限集合
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override // 涉及到用户是否禁用功能
    public boolean isEnabled() {
        return true;
    }
}
